package com.github.cooker.monitor.core.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;

/**
 * 18/1/2022 12:27 下午
 * 描述：
 *
 * @author grant
 */
public class JsonUtils {
    static ObjectMapper mapper;
    static {
        mapper = new ObjectMapper();
    }

    @SneakyThrows
    public static String toString(Object obj) {
        return mapper.writeValueAsString(obj);
    }

    @SneakyThrows
    public static <T> T toBean(String str, Class<T> cl) {
        return mapper.readValue(str, cl);
    }
}
